Shotgun Metagenomic Data Analysis    ◾    307

8.2.3.2  Mapping Reads to the Reference Genome

The following Bowtie2 commands will map the files of the samples to the human genome.

The SAM files, which contain both mapped and unmapped reads, are saved in “sam”

directory.

mkdir sam

bowtie2 -p 4 \

-x ref/hg19 \

-1 fastqdir/ERR1823587_1.fastq \

-2 fastqdir/ERR1823587_2.fastq \

-S sam/ERR1823587.sam

bowtie2 -p 4 \

-x ref/hg19 \

-1 fastqdir/ERR1823601_1.fastq \

-2 fastqdir/ERR1823601_2.fastq \

-S sam/ERR1823601.sam

bowtie2 -p 4 \

-x ref/hg19 \

-1 fastqdir/ERR1823608_1.fastq \

-2 fastqdir/ERR1823608_2.fastq \

-S sam/ERR1823608.sam

8.2.3.3  Converting SAM to BAM Format

samtools view \

-bS sam/ERR1823587.sam \

> sam/ERR1823587.bam

samtools view \

-bS sam/ERR1823601.sam \

> sam/ERR1823601.bam

samtools view \

-bS sam/ERR1823608.sam \

> sam/ERR1823608.bam

Remember that the BAM files contain mapped and unmapped reads.

8.2.3.4  Separating Metagenomic Reads in BAM Files

The next step is to remove the unmapped reads in separate files. We will use the “samtools

view” and FLAG to separate the unmapped reads.

samtools view \

-b -f 12 \

-F 256 \

sam/ERR1823587.bam \

> sam/ERR1823587_unmapped.bam

samtools view \

-b -f 12 \